package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.NoticeService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.NoticeListVo;
import com.rm.zeyou.vo.response.NoticeListResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 公告ID 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-04-07 10:56:04
 */
@Api(tags = "公告相关")
@RestController
@RequestMapping("/api/notice")
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @Resource
    private LoginUtil loginUtil;

    @ApiOperation("首页公告")
    @GetMapping("indexNotice")
    public ApiRestResponse<String> indexNotice() {
        return noticeService.indexNotice();
    }

    @ApiOperation("公告列表")
    @PostMapping("noticeList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<NoticeListResponseVo>> noticeList(@RequestBody NoticeListVo requestVo) {
        User user = loginUtil.getUser();
        return noticeService.noticeList(user.getId(),requestVo);

    }

    @ApiOperation("读取公告")
    @GetMapping("readNotice")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> readNotice(@RequestParam Long noticeId) {
        User user = loginUtil.getUser();
        return noticeService.readNotice(user.getId(),noticeId);
    }

}
